<template>
  <a-table :columns="columns" :data-source="data">
    <a slot="name" slot-scope="text">{{ text }}</a>
  </a-table>
</template>
<script>
// import bus from "@/EventBus.js";
import { listgoods } from "@/api/data";
import moment from "moment";

const columns = [
  {
    title: "商品编号",
    dataIndex: "number",
    key: "id",
    scopedSlots: { customRender: "number" }
  },
  {
    title: "商品名称",
    dataIndex: "name",
    key: "name"
  },
  {
    title: "出版社",
    dataIndex: "press",
    key: "press",
    ellipsis: true
  },
  {
    title: "销售数量",
    dataIndex: "total",
    key: "total",
    ellipsis: true
  },
  {
    title: "进货数量",
    dataIndex: "purchase",
    key: "purchase",
    ellipsis: true
  },
  {
    title: "操作时间",
    dataIndex: "createTime",
    key: "createTime",
    ellipsis: true,
    customRender: text => {
      return moment(text).format("YYYY-MM-DD HH:mm");
    }
  }
];

const data = [
  {
    key: "1",
    number: "商品编号",
    name: "订单号",
    state: "出库",
    press: "××××××",
    numbers: "xxx",
    actiontime: "xxxxxx",
    tags: ["nice", "developer"]
  },
  {
    key: "2",
    number: "商品编号",
    name: "订单号",
    state: "出库",
    press: "××××××",
    numbers: "xxx",
    actiontime: "xxxxxx",
    tags: ["nice", "developer"]
  },
  {
    key: "3",
    number: "商品编号",
    name: "订单号",
    state: "出库",
    press: "××××××",
    numbers: "xxx",
    actiontime: "xxxxxx",
    tags: ["nice", "developer"]
  },
  {
    key: "4",
    number: "商品编号",
    name: "订单号",
    state: "出库",
    press: "××××××",
    numbers: "xxx",
    actiontime: "xxxxxx",
    tags: ["nice", "developer"]
  },
  {
    key: "5",
    number: "商品编号",
    name: "订单号",
    state: "出库",
    press: "××××××",
    numbers: "xxx",
    actiontime: "xxxxxx",
    tags: ["nice", "developer"]
  },
  {
    key: "6",
    number: "商品编号",
    name: "订单号",
    state: "出库",
    press: "××××××",
    numbers: "xxx",
    actiontime: "xxxxxx",
    tags: ["nice", "developer"]
  },
  {
    key: "7",
    number: "商品编号",
    name: "订单号",
    state: "出库",
    press: "××××××",
    numbers: "xxx",
    actiontime: "xxxxxx",
    tags: ["nice", "developer"]
  },
  {
    key: "8",
    number: "商品编号",
    name: "订单号",
    state: "出库",
    press: "××××××",
    numbers: "xxx",
    actiontime: "xxxxxx",
    tags: ["nice", "developer"]
  }
];

export default {
  data() {
    return {
      data,
      columns,
      count: 0,
      params: {
        page: 1,
        perPage: 20
      }
    };
  },
  mounted() {
    this.getListgoods();
    bus.$on("list", list => {
      this.data = list;
    });
  },
  methods: {
    async getListgoods() {
      const data = await listgoods(this.params);
      const { count, list } = data;
      this.list = list || [];
      this.pagination = Object.assign({}, this.pagination, { total: count });
      this.data = list;
      console.log(this.data);
    }
  }
};
</script>
